home *** CD-ROM | disk | FTP | other *** search
/ Aminet 19 / Aminet 19 (1997)(GTI - Schatztruhe)[!][Jun 1997].iso / Aminet / gfx / conv / IFFAnimGIFAnim.lha / IFFAnim2GIFAnim.ifx next >
Text File  |  1997-03-27  |  7KB  |  229 lines

  1. /*      IFF anim to GIF anim arexx script for ImageFX 1.51+
  2.  *
  3.  * Using the original ConvertAnim.ifx source for loading in the anim, the
  4.  * extra IFFAnim>GIFAnim code is written by me, including scaling and
  5.  * cropping.
  6.  *
  7.  * (C) © 1997 by Ridwan Hughes <fox@ridhughz.demon.co.uk>
  8.  *
  9.  * Release V1.2
  10.  *
  11.  *
  12.  * Requirements:
  13.  *     The files "WhirlGIF"(v2.01), "execute" and "run" to be in c:
  14.  *     The dir "Env:ImageFX" to exist and for PIPE: to be mounted.
  15.  *     Needs the render module called Foreign.
  16.  *
  17.  * Bugs:
  18.  *     Subsequent animations will mess up totally if you break the script
  19.  *     in the middle of it's operation.
  20.  *     Won't work if you don't have the dir Env:ImageFX and also won't work
  21.  *     without the files WhirlGif and execute available in c:
  22.  *
  23.  *
  24.  * History:
  25.  *
  26.  * 1.2 Fixed the loop and timing options. Removed the disposal option as my
  27.  *     copy of ImageFX can't save transparent GIF's. Allowed user to select
  28.  *     amount of colours used in the gif anim. Space in filename bug fixed.
  29.  *     Added brightness, contrast and sharpen options which execute in that
  30.  *     order. If sharpen is selected, the images are sharpened after any
  31.  *     scaling is done. Fixed the bug when cropping an anim, the image used
  32.  *     to be 1 pixel smaller (both x and y) than indicated.
  33.  *
  34.  * 1.1 Added simple cropping into the script. Transparent option taken out,
  35.  *     as the GIF saver with ImageFX1.51 doesn't save transparent GIFs.
  36.  *     Added the disposal option for WhirlGIF v2.01.
  37.  *
  38.  * 1.0 Initial release, few people got a copy, adds the loop+transparent+
  39.  *     timing into WhirlGif's parameter input, also has image scaling.
  40.  *
  41.  */
  42.  
  43. OPTIONS RESULTS
  44.  
  45. RequestFile '"Enter Source IFF Animation:"'
  46. IF rc ~= 0 THEN EXIT 0
  47. filename = result
  48.  
  49. RequestFile '"Enter Destination GIF Animation:"'
  50. IF rc ~= 0 THEN EXIT 0
  51. outfile = result
  52.  
  53. IF outfile=filename THEN DO
  54.    RequestNotify 'Cannot save over file being read in, please re-start'
  55.    EXIT 0
  56.    END
  57.  
  58. IF EXISTS(outfile) THEN DO
  59.    RequestResponse '"Output exists.  Overwrite it?"'
  60.    IF rc ~= 0 THEN EXIT 0
  61.    END
  62.  
  63. Requestnotify 'Please select the 2nd to last frame'
  64. Requestnotify 'as most IFF anims have 2 extra frames for looping'
  65.  
  66. open(nimov,'env:ImageFX/ANIM_Frame','W')
  67. writech(nimov,'FFFF')
  68. close(nimov)
  69.  
  70. LoadBuffer d2c(34)||filename||d2c(34) force
  71.  
  72. GetMain
  73. PARSE VAR result name picwidth picheight depth .
  74.  
  75. open(nimoy,'env:ImageFX/ANIM_Frame','R')
  76. frames=c2d(readch(nimoy,4))
  77. close(nimoy)
  78. if frames=1 THEN frames=2
  79.  
  80. whirlloop=''
  81. RequestResponse 'Loop the GIF anim? (currently set to play once)'
  82. IF rc=0 THEN do
  83.    RequestNumber '"Loop how many times? (0=infinite)"' 0
  84.    whirlloop='-loop'
  85.    IF rc=0 THEN whirlloop='-loop '||result
  86.    IF result=0 THEN whirlloop='-loop'
  87.    end
  88.  
  89. whirldeelay='-time 1'
  90. RequestResponse 'Set a time delay between frames? (currently set at max speed)'
  91. IF rc=0 THEN do
  92.    RequestNumber '"Time delay between frames (1/100 fps), 1=fastest speed"' 1
  93.    IF rc=0 THEN whirldeelay='-time '||result
  94.    end
  95.  
  96. kropme=0
  97. RequestResponse 'Crop the anim?'
  98. IF rc=0 THEN do
  99.    Requestnotify 'Please click on one corner'
  100.    WaitFor SELECTUP
  101.    parse var result x y
  102.    cropx1=x
  103.    cropy1=y
  104.    RequestNotify 'Now click on the opposite corner'
  105.    WaitFor SELECTUP
  106.    parse var result x y
  107.    cropx2=x
  108.    cropy2=y
  109.    VirtualBox cropx1 cropy1 cropx2 cropy2
  110.    RequestNotify 'This is the area to be cropped'
  111.    VirtualBox cropx1 cropy1 cropx2 cropy2
  112.    if cropx1<cropx2 then do
  113.       cropx3=cropx1
  114.       cropx1=cropx2
  115.       cropx2=cropx3
  116.       end
  117.    if cropy1<cropy2 then do
  118.       cropy3=cropy1
  119.       cropy1=cropy2
  120.       cropy2=cropy3
  121.       end
  122.    cropx1=cropx1+1
  123.    cropy1=cropy1+1
  124.    crop cropx2 cropy2 cropx1-cropx2 cropy1-cropy2
  125.    kropme=1
  126.    picwidth=cropx1-cropx2
  127.    picheight=cropy1-cropy2
  128.    end
  129.  
  130. bright=0
  131. RequestResponse 'Change the brightness?'
  132. IF rc=0 THEN do
  133.    RequestSlider '"New brightness setting (127=equal):"' 0 255 127
  134.    bright=result-127
  135.    if rc ~=0 THEN bright=0
  136.    if bright ~=0 THEN brightness bright
  137.    end
  138.  
  139. kontrast=0
  140. RequestResponse 'Change the contrast?'
  141. IF rc=0 THEN do
  142.    RequestSlider '"New contrast setting (127=equal):"' 0 255 127
  143.    kontrast=result-127
  144.    if rc ~=0 THEN kontrast=0
  145.    if kontrast ~=0 THEN contrast kontrast
  146.    end
  147.  
  148. skale=0
  149. RequestResponse 'Scale the anim?'
  150. IF rc=0 THEN do
  151.    oldpicwidth=picwidth
  152.    RequestSlider '"New width:"' 2 picwidth picwidth
  153.    IF rc = 0 THEN picwidth=result;skale=1
  154.    if oldpicwidth=picwidth THEN skale=0
  155.    aspec=(picwidth/oldpicwidth)*picheight
  156.    aspectext='"New height ('||aspec||' makes it even scaling):"'
  157.    oldpicheight=picheight
  158.    RequestSlider aspectext 2 picheight aspec
  159.    IF rc = 0 THEN picheight=result;skale=1
  160.    IF oldpicheight=picheight AND oldpicwidth=picwidth THEN skale=0
  161.    end
  162.  
  163. sharp=0
  164. RequestResponse 'Sharpen the anim?'
  165. IF rc=0 THEN do
  166.    RequestSlider '"Enter Sharpen Amount:"' 0 255 0
  167.    sharp=result
  168.    if rc ~=0 THEN sharp=0
  169.    if sharp>0 THEN sharpen sharp
  170.    end
  171.  
  172. Gadget.1 = 'Number of colours in anim (Cancel=256):'
  173. Gadget.2 = '2'
  174. Gadget.3 = '4'
  175. Gadget.4 = '8'
  176. Gadget.5 = '16'
  177. Gadget.6 = '32'
  178. Gadget.7 = '64'
  179. Gadget.8 = '128'
  180. Gadget.9 = '256'
  181. colz=256
  182. ListRequest 9 Gadget
  183. IF rc = 0 THEN do
  184.    if Gadget.result=Gadget.2 THEN colz=2
  185.    if Gadget.result=Gadget.3 THEN colz=4
  186.    if Gadget.result=Gadget.4 THEN colz=8
  187.    if Gadget.result=Gadget.5 THEN colz=16
  188.    if Gadget.result=Gadget.6 THEN colz=32
  189.    if Gadget.result=Gadget.7 THEN colz=64
  190.    if Gadget.result=Gadget.8 THEN colz=128
  191.    end
  192.  
  193. open(feesh,'t:giflist','W')
  194. writeln(feesh,'pipe:gif1')
  195. do i=2 to frames
  196.   writeln(feesh,'pipe:gif'||i)
  197.   end
  198. close(feesh)
  199.  
  200. open(feesh,'t:xe','W')
  201. writeln(feesh,'run >NIL: c:whirlgif '||whirlloop||' '||whirldeelay||' -o '||d2c(34)||outfile||d2c(34)||' -i t:giflist')
  202. close(feesh)
  203. address command 'execute t:xe'
  204.  
  205. SetPrefs Undo Off
  206. Menu Render
  207. SetRender Foreign
  208. Render Mode Lores Nolace
  209. Render Colors colz
  210.  
  211.  
  212. DO i = 1 to frames
  213.   LoadBuffer d2c(34)||filename||d2c(34) Force i           /* load a frame */
  214.   IF rc ~= 0 THEN LEAVE                      /* oops... end of file, exit */
  215.   IF kropme=1 then crop cropx2 cropy2 cropx1-cropx2 cropy1-cropy2 /* crop */
  216.   IF bright ~=0 THEN brightness bright           /* change the brightness */
  217.   IF kontrast ~=0 THEN contrast kontrast           /* change the contrast */
  218.   IF skale=1 then Scale picwidth picheight             /* scale the image */
  219.   IF sharp>0 THEN sharpen sharp                      /* sharpen the image */
  220.   Render Go                               /* uses current render settings */
  221.   SaveRenderedAs GIF 'pipe:gif'||i                   /* save GIF to pipe: */
  222.   END
  223.  
  224. SetPrefs Undo On
  225.  
  226. Requestnotify 'Your GIF anim is now complete.'
  227.  
  228. EXIT 0
  229.